package com.zh.springcloud.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @Description:
 * @ClassName JwtTokenStoreConfig
 * @date: 2021.11.14 19:40
 * @Author: zhanghang
 */
@Configuration
public class JwtTokenStoreConfig {

	/**
	 * description: 使用jwtToken Store
	 * date: 2021年-11月-14日 19:45
	 * author: zhanghang
	 * 
	 * @param 
	 * @return org.springframework.security.oauth2.provider.token.TokenStore
	 */ 
	@Bean("jwtTokenStore")
	public TokenStore jwtTokenStore(){
		return new JwtTokenStore(jwtAccessTokenConverter());
	}

	/**
	 * description: 转换器，将原来生成的 access_token转换成 jwtToken
	 * date: 2021年-11月-14日 19:43
	 * author: zhanghang
	 *
	 * @param
	 * @return org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter
	 */
	@Bean
	public JwtAccessTokenConverter jwtAccessTokenConverter(){
		JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
		// 设置秘钥
		jwtAccessTokenConverter.setSigningKey("123456");
		return jwtAccessTokenConverter;
	}
	
	/**
	 * description: jwt 扩展信息 
	 * date: 2021年-11月-28日 18:55
	 * author: zhanghang
	 * 
	 * @param 
	 * @return com.zh.springcloud.config.JwtTokenEnhancer
	 */ 
	@Bean
	public JwtTokenEnhancer jwtTokenEnhancer(){
		return new JwtTokenEnhancer();
	}
}
